<?php
/**
 * Description of IndexController
 *
 * @author Shang
 */
class Front_IndexController extends zShang_Controller_Action {
    public $tb_games;
    public $tb_clubs_tours;
    public $games;
    public $frontConfig;
    
    public function init() {
        parent::init();
        
        $this->tb_games = Core_Models_DbTable_Games::getInstance();
        $this->tb_clubs_tours = Core_Models_DbTable_ClubsTours::getInstance();
        $this->frontConfig = Zend_Registry::getInstance()->get('frontConfig');
        $this->view->frontConfig= $this->frontConfig;
    }
    public function indexAction() {       
        // Params
        $page = $this->_getParam('page', 0);
        $params = array(
            'id_tour'   =>  1,
            'season'    =>  '2012-2013'
        );
        // Form
        $form = new Front_Forms_Games();
        if ($this->getRequest()->isGet()) {
             $params = array_merge($params, $_GET);
            $form->populate($params);
        }
        
        // Tournaments
        $tournaments = $this->tb_games->getTournaments();
        if (!empty($tournaments)) {
            $form->populateTournaments($tournaments->toArray());
        }
        // Seasons
        $seasons = $this->tb_games->getSeasons($params);
        if (!empty($seasons)) {
            $form->populateSeasons($seasons->toArray());
        }
        // Rounds
        $rounds = $this->tb_games->getRounds($params);        
        if (!empty($rounds)) {
            $form->populateRounds($rounds->toArray());
        }
        // Clubs
        $clubs = $this->tb_clubs_tours->getClubs($params);
        if (!empty($clubs)) {
            $form->populateClubs($clubs->toArray());
        }
        
        // Get games
        $paginator = Zend_Paginator::factory($this->tb_games->getSelectGames($params));
        $paginator->setItemCountPerPage(ITEMS_PER_PAGE);
        $paginator->setCurrentPageNumber($page);
        
        // View
        $this->view->paginator = $paginator;
        $this->view->query = $params;
        $this->view->form = $form;
    }
    
    public function clubAction() {
        
    }
    public function todayAction() {
        
    }
}